/* 
This do file produces online appendix tables associated with the article: 
Wood, T, Hoy, C & Pryke, J "The effect of geostrategic competition 
on public attitudes to aid", Journal of Experimental Political Science.

This do file is focused on the NEW ZEALAND DATA.

Please email all questions to: terence.wood@anu.edu.au/terencewoodnz@gmail.com

First creates balance table for New Zealand (control and each treatment group),
which shows how well balanced groups are across key sociodemographic & political
traits.

Second runs alternate regression models for New Zealand questions.

This is done by question/dependent variable of interest, to produce full table 
of results for the question.
	The full table of results for the question contains:
	OLS no controls;
	Logistic bivariate;
	Logistic with full controls; 
	&
	Multinomial logistic (with and without controls). (Note that mlogit results
	are placed in their own table).
	
All tables are output into a single rtf file.

Do file coded in Stata version 14. 

You need to install the estout package before running this code:
http://repec.sowi.unibe.ch/stata/estout/	

You will need to install the ietoolkit package before running this code:
https://blogs.worldbank.org/impactevaluations/ie-analytics-introducing-ietoolkit
	
*/

********************************************************************************
*****************************Preliminaries**************************************
********************************************************************************

set more off

cd "ENTER YOUR WORKING DIRECTORY HERE"

use "2 NZ data JEPS FINAL", clear


********************************************************************************
******************************Balance Table*************************************
********************************************************************************

//Create temporary political dummy variable indicating left wing preference
gen left = .
replace left = 0 if partysimple==1
replace left = 0 if partysimple==3
replace left = 1 if partysimple==2

//Create balance table
iebaltab urban over60 male manprof incomecont left, ///
grpvar(treatment) save(China_Balance_New Zealand)

//Tidy up
drop left


********************************************************************************
**************************Full Regression Models********************************
********************************************************************************

**************************Attitudes to aid volume*******************************

estimates clear

****Simple OLS to test means (no controls) between treatment groups
qui reg toomuchaid i.treatment
	estimates store lv, title("Too much aid (OLS)")

****Logit on "too much aid" to compare bivariate model with model with controls

//Basic model no controls
qui logit toomuchaid i.treatment 
	estimates store lvsimple, title("Too much aid (logit)")

//Model full controls	
qui logit toomuchaid i.treatment ///
	i.urban i.over60 i.male i.partysimple i.manprof incomecont
	
	estimates store lvfull, title("Too much aid (logit w controls)")

//Table of results	
esttab lv lvsimple lvfull ///
using A_NZ_results.rtf, replace b(2) se(2) ///
label nonumber mtitle nobase starlevel(* 0.1 ** 0.05 *** 0.01) ///
nogaps title("Too much aid")


****Mlogit to study impact of treatments across all response categories
//useful read: https://stats.idre.ucla.edu/stata/dae/multinomiallogistic-regression/
estimates clear

//Create simplified volume variable
gen simplevol=.
replace simplevol=3 if aidvol==4|aidvol==5
replace simplevol=2 if aidvol==3
replace simplevol=1 if aidvol==1|aidvol==2
label define svlab 3 "Too little" 2 "Right amount" 1 "Too much"
label values simplevol svlab

//simple model, no controls
qui mlogit simplevol i.treatment

//Predicted marginal effects of change between control and treatment groups
qui margins, dydx(treatment) atmeans post fvlabel
estimates store mvsimple, title("No controls")

//model with controls
qui mlogit simplevol i.treatment ///
i.urban i.over60 i.male i.partysimple i.manprof incomecont 

//Predicted marginal effects of change between control and treatment groups
qui margins, dydx(treatment) atmeans post
estimates store mvfull, title("With controls")

//Produce table of results, manually labelling values for each category
esttab mvsimple mvfull ///
using A_NZ_results.rtf, append b(2) se(2) ///
label nonumber mtitle nobase noomitted starlevel(* 0.1 ** 0.05 *** 0.01) ///
nogaps eqlabels("Measured") ///
coeflabels(1._predict  "Too much aid" 2._predict  "About right" 3._predict  "Too little aid") ///  
title("Aid volume (multinomial logistic)")

****Tidy up
estimates clear
drop simplevol
label drop svlab

**************************Attitudes to Pacific Focus****************************

estimates clear

****Simple OLS to test means (no controls) between treatment groups
qui reg morepac i.treatment
	estimates store op, title("More Pacific (OLS)")

	
****Logit on "more focus on pacific" to compare bivariate with model with controls

//Simple model
qui logit morepac i.treatment 
	estimates store lpsimple, title("More Pacific (logit)")

//Controls included	
qui logit morepac i.treatment ///
	i.urban i.over60 i.male i.partysimple i.manprof incomecont
	
	estimates store lpfull, title("More Pacific (logit w controls)")
	
esttab op lpsimple lpfull ///
using A_NZ_results.rtf, append b(2) se(2) ///
label nonumber mtitle nobase starlevel(* 0.1 ** 0.05 *** 0.01) ///
nogaps title("More to Pacific")


****Mlogit to study impact of treatments across all response categories

estimates clear

//Bivariate mlogit
qui mlogit pacfocus i.treatment

//Predicted marginal effects of change between control and treatment groups
qui margins, dydx(treatment) atmeans post fvlabel
estimates store mpsimple, title("No controls")


//Mlogit with controls
qui mlogit pacfocus i.treatment ///
i.urban i.over60 i.male i.partysimple i.manprof incomecont 

//Predicted marginal effects of change between control and treatment groups
qui margins, dydx(treatment) atmeans post
estimates store mpfull, title("With controls")

//Produce table of results, manually labelling values for each category
esttab mpsimple mpfull ///
using A_NZ_results.rtf, append b(2) se(2) ///
label nonumber mtitle nobase noomitted starlevel(* 0.1 ** 0.05 *** 0.01) ///
nogaps eqlabels("Measured") ///
coeflabels(1._predict "More to Pacific" 2._predict  "Same" 3._predict  "Less to Pacific") ///
title("Share to pacific (multinomial logistic)")  

****Tidy up
estimates clear



**************************Attitudes to Aid Purpose****************************

****Simple OLS to test means (no controls) between treatment groups
qui reg favournz i.treatment
	estimates store og, title("Favour NZ (OLS)")

	
****Logit on "more geostrategic" to compare bivariate with model with controls	
qui logit favournz i.treatment 
	estimates store lgsimple, title("Favour NZ (logit)")
	
qui logit favournz i.treatment ///
	i.urban i.over60 i.male i.partysimple i.manprof incomecont
	
	estimates store lgfull, title("Favour NZ (logit w controls)")
	
esttab og lgsimple lgfull ///
using A_NZ_results.rtf, append b(2) se(2) ///
label nonumber mtitle nobase starlevel(* 0.1 ** 0.05 *** 0.01) ///
nogaps title("Favour aid used to advance New Zealand interests")

estimates clear


****Mlogit to study impact of treatments across all response categories

//Create a simplified purpose categorical variable
gen simplepurpose=.
replace simplepurpose=1 if favournz==1
replace simplepurpose=2 if favourpoor==1
label define splab 1 "NZ" 2 "Poor"
label values simplepurpose splab

//Bivariate mlogit
qui mlogit simplepurpose i.treatment

//Predicted marginal effects of change between control and treatment groups
qui margins, dydx(treatment) atmeans post fvlabel
estimates store mpsimple, title("No controls")

//mlogit with controls
qui mlogit simplepurpose i.treatment ///
i.urban i.over60 i.male i.partysimple i.manprof incomecont

//Predicted marginal effects of change between control and treatment groups
qui margins, dydx(treatment) atmeans post
estimates store mpfull, title("With controls")

//Produce table of results, manually labelling values for each category
esttab mpsimple mpfull ///
using A_NZ_results.rtf, append b(2) se(2) ///
label nonumber mtitle nobase noomitted starlevel(* 0.1 ** 0.05 *** 0.01) ///
nogaps eqlabels("Measured") ///
coeflabels(1._predict "Favour NZ" 2._predict  "Favour poor") ///
title("Aid help New Zealand or help poor (multinomial logistic)")  


****Tidy up
estimates clear
drop simplepurpose
label drop splab


